package iedcyt.acute.dataAccess.dao.endnote;

import iedcyt.acute.dataAccess.domain.endnote.REC_Xml;
import iedcyt.acute.dataAccess.generic.SpringDao;
import iedcyt.acute.dataAccess.idao.endnote.IREC_XmlDao;

import java.util.List;



public class REC_XmlDao extends SpringDao implements IREC_XmlDao  {

	@Override
	public void create() {
		//comprobamos si la tabla existe y si no la creamos
		try {
			_jdbcTemplate.queryForInt("select count(*) from REC_Xml");
		} catch (Exception e) {
			_jdbcTemplate.execute("CREATE TABLE REC_Xml (id numeric, rec memo, notes varchar(255))");
		}
	}
		
	@Override
	public void deleteAll() {
		
		_jdbcTemplate.update("DELETE from REC_Xml");
	}

	

	@Override
	public void insert(REC_Xml doc) {
	
	 _jdbcTemplate.update("INSERT INTO REC_Xml (id, rec, notes) VALUES (?,?,?)",
				new Object[] { doc.get_id(), doc.get_xml(), doc.get_notes() });
		
		
	}
	
	@Override
	public void update(REC_Xml doc) {
	
	 _jdbcTemplate.update("UPDATE REC_Xml SET rec = ?, notes = ? WHERE id = ?",
				new Object[] { doc.get_xml(), doc.get_notes(), doc.get_id() });
		
		
	}
	
	
	@Override
	public List<REC_Xml> select(int id) {
		
		return _jdbcTemplate.query(
						"SELECT id, rec, notes FROM REC_Xml WHERE id = ?",
						new Object[] { id },
						new REC_XmlRowMapper());
	}

	
	@Override
	public void delete(int id) {
	
		_jdbcTemplate.update("DELETE from REC_Xml WHERE id=?",
				new Object[] { id  });
		
	}

	@Override
	public int selectMaxId() {
		return _jdbcTemplate.queryForInt("SELECT MAX(id) FROM REC_Xml");
	}

	

		

	

	
	
}

